<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>
FFmpegSource2 User Manual
</title>
<link href="style.css" media="screen" rel="Stylesheet" type="text/css" />
</head>
<body>
<div class="maincontent">
<h1>FFmpegSource2 User Manual</h1>
<p>
Opens files using FFmpeg and nothing else. May be frame accurate on good days. The source is MIT licensed and can be obtained from <a href="http://code.google.com/p/ffmpegsource/source/checkout">http://code.google.com/p/ffmpegsource/source/checkout</a>. The precompiled binary is GPL3 licensed. If you are religious you may consider this the second coming.
</p>

<h2>Donate</h2>
<p>
Donate if you like this software. Collecting weird clips from the internet and making them play takes more time than you'd think. 
</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<p>
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="6944567" />
<input type="image" src="https://www.paypal.com/en_GB/i/btn/btn_donate_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online." />
<img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</p>
</form>


<h2>Limitations</h2>
<ul>
<li>Requires <a href='http://haali.cs.msu.ru/mkv/'>Haali's Media Splitter</a> if ogm or mpeg ps/ts is to be opened.</li>
<li>Haali's splitter requires transport streams to be cut at packet boundaries. Use <a href='http://forum.doom9.org/showthread.php?t=125447'>TsRemux</a> to fix the stream before trying to open it.</li>
<li>Because of LAVF's demuxer most raw streams will fail to work properly such as elementary h264 and other mpeg video streams.</li>
<li>FFAudioSource() will have to remake any index implicitly created by FFVideoSource() and therefore code like
<pre>
AudioDub(FFVideoSource(X), FFAudioSource(X))
</pre>
will require two indexing passes. Apart from the time consumed this is harmless. To work around it open the audio first
<pre>
A = FFAudioSource(X)
V = FFVideoSource(X)
AudioDub(V, A)
</pre>
or use FFIndex().
<pre>
FFIndex(X)
AudioDub(FFVideoSource(X), FFAudioSource(X))
</pre>
</li>
</ul>

<h2>Known issues</h2>
<ul>
<li>There will appear decoding artifacts on h264 in transport streams.</li>
<li>FFIndex() will silently ignore fatal decoding errors when indexing. This means that indexing a specific track may have failed even if FFIndex() succeeds.</li>
</ul>

<h2>Compatibility</h2>
<ul>
<li>AVI, MKV, MP4, FLV: Frame accurate</li>
<li>WMV: Frame accurate(?) but avformat seems to pick keyframes relatively far away</li>
<li>OGM: Frame accurate(?)</li>
<li>VOB, MPG: Seeking seems to be off by one or two frames now and then</li>
<li>M2TS, TS: Seeking seems to be off a few frames here and there</li>
<li>Image files: Most formats can be opened if seekmode=-1 is set, no animation support</li>
</ul>

<h2>Functions in FFMS2.dll</h2>
<p>
<b>FFIndex(string source, string cachefile = source + ".ffindex", int indexmask = -1, int dumpmask = 0, string audiofile = "%sourcefile%.%trackzn%.w64", int errorhandling = 3, bool overwrite = false)</b><br />
 Used to invoke indexing separately with a few additional options and to write audio tracks to disk as wave64 files. It can be useful to use to avoid remaking the index twice or if some audio tracks are unsupported/broken and cannot be indexed properly.
</p>

<p>
<b>FFVideoSource(string source, int track, bool cache = true, string cachefile = source + ".ffindex", int fpsnum = -1, int fpsden = 1, string pp, int threads = -1, string timecodes, int seekmode = 1, int rffmode = 0, int width = -1, int height = -1, string resizer = "BICUBIC", string colorspace = "")</b><br />
 Opens video, will invoke indexing of all video tracks if no usable index is found.
</p>

<p>
<b>FFAudioSource(string source, int track, bool cache = true, string cachefile = source + ".ffindex", int adjustdelay = -1)</b><br />
 Opens audio, will invoke indexing of all tracks if no index exists or the requested track is not present in the index.
</p>

<p>
<b>FFPP(clip, string pp)</b><br />
  Separate postprocessing which also seems to include a few simple deinterlacers. Use the pp argument in FFVideoSource whenever possible as it will also have access to the video quantizers and thus adapt better to the video.
</p>

<p>
<b>SWScale(clip, int width = -1, int height = -1, string resizer = "BICUBIC", string colorspace = "")</b><br />
  A resizing/colorspace conversion filter that does nothing special at all. May be useful in some cases just because it does not do things exactly like avisynth.
</p>

<p>
<b>FFSetLogLevel(int Level = -8)</b><br />
  Sets the log FFmpeg logging level. Defaults to quiet (-8) and the FFmpeg default is 16. All possible different values can be found in avutil/log.h.
</p>

<p>
<b>FFGetLogLevel()</b><br />
  Returns the current level of logging as an int.
</p>

<h2>Functions in FFMS2.avsi</h2>
<p>
<b>FFmpegSource2(string source, int vtrack = -1, int atrack = -2, bool cache = true,
 string cachefile = source + ".ffindex", int fpsnum = -1, int fpsden = 1, string pp, int threads = -1,
	string timecodes, int seekmode = 1, bool overwrite = false, int width = -1, int height = -1, string resizer = "BICUBIC", string colorspace = "", int rffmode = 0,
	int adjustdelay = -1)</b><br />
 Approximates the syntax later versions of the 1.x series. Can be convenient to use with atrack=-1 to load both audio and video at the same time. Note that the adjustdelay parameter may need to be specified for the expected behavior if a video track other than the first is selected.
</p>

<p>
<b>FFImageSource(string source, int width = -1, int height = -1, string resizer = "BICUBIC", string colorspace = "")</b><br />
 Another alias for FFVideoSource with the options set optimally for using it as an image reader. Disables caching and seeking for maximum compatiblity.
</p>

<p>
<b>FFFormatTime(int ms)</b><br />
 A helper function to format time given in milliseconds into a h:mm:ss.ttt string.
</p>

<p>
<b>FFInfo(clip c, bool framenum = true, bool frametype = true, bool cfrtime = true, bool vfrtime = true)</b><br />
 A helper function to show general information about the current frame. Note that not all values are exported in all source modes and will therefore not always be shown.
</p>

<h2>Function arguments</h2>
<p>
<b>source:</b>
  Source file.
</p>

<p>
<b>indexmask &amp; dumpmask:</b>
  Which audio tracks to index/write to disk. Dumping a track also implies indexing since the same work has to be done anyway. It is a binary mask meaning that 7 corresponds to writing tracks 1-3. Non-audio tracks are ignored. -1 writes all tracks.
</p>

<p>
<b>audiofile:</b>
  The filename to use for dumped audio tracks. Make sure to include a track number variable to avoid multiple file access errors. The variables are case sensitive. The available variables are:<br />
<b>%sourcefile%</b> - same as the source argument, the file the audio is decoded from<br />
<b>%trackn%</b> - the track number<br />
<b>%trackzn%</b> - the track number zero padded to 2 digits<br />
<b>%samplerate%</b> - self explanatory<br />
<b>%channels%</b> - self explanatory<br />
<b>%bps%</b> - bits per sample<br />
<b>%delay%</b> - delay, or more exactly the first timestamp encountered in the audio stream
</p>

<p>
<b>overwrite:</b>
  Forces reindexing even if a valid index already exists. May be useful for trackmask changes or testing.
</p>

<p>
<b>track:</b>
  Track number as seen by the relevant demuxer. Starts from 0, -1 means it will pick the first suitable track. This may however NOT be the first video/audio track found if it is not indexed but a later one is.
</p>

<p>
<b>fpsnum &amp; fpsden:</b>
  For VFR -&gt; CFR conversion. Setting fpsnum &lt;= 0 means a 1:1 relation with the encoded frames.
</p>

<p>
<b>timecodes:</b>
  File to output timecodes to. If the file exists it will be overwritten.
</p>

<p>
<b>cache:</b>
  Write indexing information to a file for later use. This setting controls both loading of existing indices and the writing of new ones.
</p>

<p>
<b>cachefile</b>
  Where to write the cache information.
</p>

<p>
<b>pp:</b>
  See the table below for a full description, an empty string means no processing. It is recommended to avoid the autoq option since it's currently unknown what effect it will have on the processing.
</p>

<p>
<b>threads:</b>
  Sets the number of decoder threads used. Defaults to the number of logical cpus reported by windows. Ignored by lavc if the used decoder doesn't implement it.
</p>

<p>
<b>seekmode:</b>
  Control how seeking is handled, has no effect on matroska or haali splitter opened files which always use the equivalent of seekmode=1.<br />
    <b>-1:</b> linear access without rewind, will throw an error if each successive requested frame number isn't bigger than the last one, only intended for opening images but might work on well with some obscure video format<br />
    <b>0:</b> linear access, the definition of slow but should make some formats "usable"<br />
    <b>1:</b> safe normal, bases seeking decisions on the reported keyframe positions<br />
    <b>2:</b> unsafe normal, same as 1 but no error will be thrown if the exact destination has to be guessed<br />
    <b>3:</b> aggressive, seek in the forward direction even if no closer keyframe is known to exist, only useful for testing and containers where avformat doesn't report keyframes properly
</p>

<p>
<b>rffmode:</b>
  Controls how RFF flags in the video stream is treated.<br />
    <b>0:</b> Ignore all flags<br />
    <b>1:</b> Honor all pulldown flags<br />
    <b>2:</b> Equivalent to force film<br />
  Note that setting rffmode &gt; 0 will throw an error if the video stream has no RFF flags at all. When engaged it will also make the output be assumed as CFR, disallow vertical scaling and setting the output colorspace. FFPICT_TYPE will also not be set as the output is a combination of several frames. Other subtle behavior changes may also exist.
</p>

<p>
<b>width &amp; height:</b>
  Width and height to resize to. Value below or equal to 0 is the same as specifying the input dimensions.
</p>

<p>
<b>resizer:</b>
  Selects the resizer used for resampling the chroma planes and normal resizing. The available methods are: FAST_BILINEAR, BILINEAR, BICUBIC, X, POINT, AREA, BICUBLIN, GAUSS, SINC, LANCZOS and SPLINE.
</p>

<p>
<b>colorspace:</b>
  The colorspace to convert to. The names are YV12, YUY2, RGB24, RGB32 and the empty string for same as input.
</p>

<p>
<b>errorhandling:</b>
  Controls what happens when an audio decoding error is encountered.<br />
    <b>0:</b> Abort indexing<br />
    <b>1:</b> Clear the affected track and continue<br />
    <b>2:</b> Stop indexing the track but keep all the index entries so far<br />
    <b>3:</b> Continue anyway<br />
</p>

<p>
<b>adjustdelay:</b>
  Try to apply a suitable delay to the audio track. -1 is the default mode and should produce correct results in most cases<br />
    <b>-3:</b> No delay adjustment<br />
    <b>-2:</b> Adjust relative to time 0<br />
    <b>-1:</b> Adjust relative to the first video track, adjusts the delay relative to time 0 if no video track is present<br />
    <b>Any valid track number:</b> Adjust relative to the specified track<br />
</p>

<h2>Exported Avisynth variables</h2>
<p>
<b>FFSAR_NUM, FFSAR_DEN, FFSAR:</b>
 The playback aspect ratio specified by the container. FFSAR_NUM and FFSAR_DEN make up the rational number of the ratio and FFSAR is only provided for convenience and may not be set in case it cannot be calculated (FFSAR_DEN=0).
</p>

<p>
<b>FFCROP_LEFT, FFCROP_RIGHT, FFCROP_TOP, FFCROP_BOTTOM:</b>
 The on playback cropping specified by the container.
</p>

<p>
<b>FFCOLOR_SPACE:</b>
 The output colorimetry. Matches the values used by ColorMatrix() as input.
</p>

<p>
<b>FFCOLOR_RANGE:</b>
 The range used by the output.<br />
    <b>0:</b> Unknown/unspecified<br />
    <b>1:</b> Limited-range<br />
    <b>2:</b> Full-range<br />
</p>


<p>
<b>FFPICT_TYPE:</b>
 The picture type of the most recently requested frame as the ascii number of the character listed below. Use Chr() to convert it to an actual letter in avisynth. Use after_frame=true in Avisynth's conditional scripting for proper results. Only set when rffmode=0. The FFmpeg source definition of the characters:
</p>
<pre>
I: Intra
P: Predicted
B: Bi-dir predicted
S: S(GMC)-VOP MPEG4
i: Switching Intra
p: Switching Predicted
b: FF_BI_TYPE (no good explanation available)
?: Unknown
</pre>

<p>
<b>FFVFR_TIME:</b>
 The actual time of the source frame in milliseconds. Only set when no type of CFR conversion is being done (rffmode and fpsnum left at their defaults).
</p>



<h2>PP string format</h2>
<pre>
Available postprocessing filters:
Filters                        Options
short  long name       short   long option     Description
*      *               a       autoq           CPU power dependent enabler
                       c       chrom           chrominance filtering enabled
                       y       nochrom         chrominance filtering disabled
                       n       noluma          luma filtering disabled
hb     hdeblock        (2 threshold)           horizontal deblocking filter
       1. difference factor: default=32, higher -&gt; more deblocking
       2. flatness threshold: default=39, lower -&gt; more deblocking
                       the h &amp; v deblocking filters share these
                       so you can't set different thresholds for h / v
vb     vdeblock        (2 threshold)           vertical deblocking filter
ha     hadeblock       (2 threshold)           horizontal deblocking filter
va     vadeblock       (2 threshold)           vertical deblocking filter
h1     x1hdeblock                              experimental h deblock filter 1
v1     x1vdeblock                              experimental v deblock filter 1
dr     dering                                  deringing filter
al     autolevels                              automatic brightness / contrast
f      fullyrange                              stretch luminance to (0..255)
lb     linblenddeint                           linear blend deinterlacer
li     linipoldeint                            linear interpolating deinterlace
ci     cubicipoldeint                          cubic interpolating deinterlacer
md     mediandeint                             median deinterlacer
fd     ffmpegdeint                             ffmpeg deinterlacer
l5     lowpass5                                FIR lowpass deinterlacer
de     default                                 hb:a,vb:a,dr:a
fa     fast                                    h1:a,v1:a,dr:a
ac                                             ha:a:128:7,va:a,dr:a
tn     tmpnoise        (3 threshold)           temporal noise reducer
                     1. &lt;= 2. &lt;= 3.            larger -&gt; stronger filtering
fq     forceQuant      &lt;quantizer&gt;             force quantizer
Usage:
&lt;filterName&gt;[:&lt;option&gt;[:&lt;option&gt;...]][[,|/][-]&lt;filterName&gt;[:&lt;option&gt;...]]...
long form example:
vdeblock:autoq/hdeblock:autoq/linblenddeint    default,-vdeblock
short form example:
vb:a/hb:a/lb                                   de,-vb
more examples:
tn:64:128:256
</pre>

</div>

</body>
</html>
